package net.tankwar.event;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import net.jumpengine.bean.LinesBase;
import net.jumpengine.bean.TextRect;
import net.jumpengine.inter.IStateEvent;
import net.jumpengine.po.Border;
import net.jumpengine.ui.ButtonBase;
import net.jumpengine.ui.CheckBox;
import net.jumpengine.ui.ImageButton;
import net.jumpengine.util.UDraw;
import net.jumpengine.util.UIO;
import net.jumpengine.bean.RectBase;

public class EditStateEvent implements IStateEvent {
	private boolean load=false;
	
	private LinesBase rect;
	private TextRect debugText;
	
	private List<ImageButton> list=new ArrayList<>();
	private ImageButton tmp;
	
	private RectBase moveIn,select;
	
	@Override
	public void setBackImage(Image image) { }

	@Override
	public boolean isLoaded() {
		return load;
	}

	@Override
	public void load() {
		rect=new LinesBase(144, 0, 1296, 792, 72, 72, Color.LIGHTGREEN, 2, 0);
		
		Font f=UDraw.getFont("楷体", 16, true, false);
		
		new ButtonBase(16, 16, 112, 40, "保  存").setFont(f);
		
		new ButtonBase(16, 80, 112, 40, "打  开").setFont(f);
		
		new CheckBox(22, 135, 100, 13, "显示对齐网格");
		
		Border b=new Border(4, 5);
		b.setColor(Color.web("3366FF"));
		debugText=new TextRect(4, 170, 136, 40, "DEBUG模式\n将编辑系统地图", b);
		debugText.setFont(UDraw.getFont("黑体", 13, true, false));
		debugText.setColor(Color.web("FFFFCC"));
		
		Map<String, Image> map = UIO.loadImageByPro("/image.pro", null, this.getClass());
		
		tmp=new ImageButton(4, 227, 64, 64, map.get("map.qiang"),0,0,72,72);
		list.add(tmp);
		
		tmp=new ImageButton(76, 227, 64, 64, map.get("map.pingdi"),0,0,72,72);
		list.add(tmp);
		
		tmp=new ImageButton(4, 301, 64, 64, map.get("map.shui"),0,0,216,216);
		list.add(tmp);
		
		tmp=new ImageButton(76, 301, 64, 64, map.get("map.jinshu"),0,0,72,72);
		list.add(tmp);
		
		tmp=new ImageButton(4, 375, 64, 64, map.get("map.lu"),0,0,72,72);
		list.add(tmp);
		
		tmp=new ImageButton(76, 375, 64, 64, map.get("map.shu"));
		list.add(tmp);
		
		tmp=new ImageButton(4, 449, 64, 64, map.get("map.leida"));
		list.add(tmp);
		
		tmp=new ImageButton(76, 449, 64, 64, map.get("map.shuaguai"),0,0,72,72);
		list.add(tmp);
		
		tmp=new ImageButton(4, 522, 64, 64, map.get("map.tanke11"));
		list.add(tmp);
		
		tmp=new ImageButton(76, 522, 64, 64, map.get("map.bianjie"));
		list.add(tmp);
		
		tmp=new ImageButton(4, 596, 64, 64, map.get("map.xiangpica"));
		list.add(tmp);
		
		moveIn=new RectBase(-80, -80, 72, 72, Color.ANTIQUEWHITE, 2,1);
		select=new RectBase(-80, -80, 72, 72, Color.LIGHTCYAN, 2,1);
		
		load=true;
	}

	@Override
	public void show() { }

	@Override
	public void pause() { }

	@Override
	public void end() { }

	public LinesBase getRect() {
		return rect;
	}

	public int find(ImageButton btu) {
		return list.indexOf(btu);
	}
	
	public void setMoveIn(ImageButton btu) {
		if(btu==null) {
			moveIn.setLocation(-80, -80);
		}else {
			moveIn.setLocation(btu.getX()-4, btu.getY()-4);
		}
	}
	
	public void setSelect(ImageButton btu) {
		if(btu==null) {
			select.setLocation(-80, -80);
		}else {
			select.setLocation(btu.getX()-4, btu.getY()-4);
		}
	}
}
